package face.yuque;

import java.util.Arrays;

/**
 * @author spf
 * @date 2024/12/12
 * @time 16:35
 */

//两数之和
//方法一：暴力算法
public class TwoSum {

    public static void main(String[] args) {
        int[] nums = {1, 2, 3, 4, 6, 5};
        int target = 10;
        System.out.println(Arrays.toString(twoSum(nums, target)));
    }

    private static int[] twoSum(int[] nums, int target) {
        for (int i = 0; i < nums.length; i++) {
            for (int j = i + 1; j < nums.length; j++) {
                if (nums[i] + nums[j] == target) {
                    return new int[]{i, j};
                }
            }
        }
        return new int[]{0};
    }

}
